package com.kk.xhr.model.assembler;

import com.kk.xhr.common.pojo.CandidateStatusEnum;
import com.kk.xhr.common.pojo.GenderEnum;
import com.kk.xhr.model.dto.CandidateDTO;
import com.kk.xhr.model.entity.Candidate;
import org.mapstruct.Mapper;
import org.mapstruct.factory.Mappers;

/**
 * 候选人数据转换工具类
 *
 * @author kkmystery
 * @version 1.0 2021/2/28 11:31
 * @since 1.0.0
 */
@Mapper(componentModel = "spring")
public interface CandidateStructKit {

    CandidateStructKit INSTANCE = Mappers.getMapper(CandidateStructKit.class);

    /**
     * dto -> entity
     *
     * @param dto dto
     * @return entity
     */
    Candidate toEntity(CandidateDTO dto);

    /**
     * entity -> dto
     *
     * @param entity entity
     * @return dto
     */
    CandidateDTO toDto(Candidate entity);

    /**
     * CandidateStatusEnum类型 byte -> enum
     *
     * @param status 状态
     * @return CandidateStatusEnum
     */
    default CandidateStatusEnum statusConvertor(Byte status) {
        if (null == status) {
            return null;
        }
        return CandidateStatusEnum.from(status);
    }

    /**
     * CandidateStatusEnum类型 enum -> byte
     *
     * @param status 状态
     * @return byte
     */
    default Byte statusConvertor(CandidateStatusEnum status) {
        if (null == status) {
            return null;
        }
        return status.getValue();
    }

    /**
     * GenderEnum类型 byte -> enum
     *
     * @param from 性别byte
     * @return GenderEnum
     */
    default GenderEnum genderConvertor(Byte from) {
        if (null == from) {
            return null;
        }
        return GenderEnum.from(from);
    }

    /**
     * GenderEnum类型 enum -> byte
     *
     * @param from 性别枚举
     * @return byte
     */
    default Byte genderConvertor(GenderEnum from) {
        if (null == from) {
            return null;
        }
        return from.getValue();
    }
}
